﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.IO;

namespace ResourceEditor.Core.ResourceDataObjects
{
    public class ResourceDataBitmap : ResourceData<Image>, ISupportFileResource
    {
        #region Ctor
        public ResourceDataBitmap(ResourceFile container)
            : base(container)
        {

        }
        #endregion

        #region IFileObject Members

        public void Add(string fileName)
        {
            try
            {
                FileInfo info = new FileInfo(fileName);
                Add(info.Name, Image.FromFile(fileName));
            }
            catch(Exception ex)
            {
                Logger.Exception(ex);
                throw;
            }
        }

        public void ChangeItem(string key, string fileName)
        {
            try
            {
                ChangeItem(key, Image.FromFile(fileName));
            }
            catch (Exception ex)
            {
                Logger.Exception(ex);
                throw;
            }
        }

        public string GetExtension(string key)
        {
            return this[key].Current.ImageType();
        }

        public void Export(string key, string fileName)
        {
            try
            {
                this[key].Current.Save(fileName);
            }
            catch (Exception ex)
            {
                Logger.Exception(ex);
                throw;
            }
        }

        #endregion
    }
}
